Method for creating face replacement database

ABSTRACT

A method for creating a face replacement database includes steps of creating a face database for storing a plurality of replaced images with a face image rotation angle by using a method for estimating a 3D vector angle from a 2D face image, and defining a region to be replaced in the replaced image. The method for estimating a 3D vector angle from a 2D face image includes the steps of creating a feature vector template; detecting a corner of eye and mouth in a face image; defining a sharp point in a vertical direction of the quadrilateral plane, and converting the vertices into 3D coordinates; computing the four vectors from the sharp point to the four vertices to obtain a vector set, and matching the vector set with the feature vector model to obtain an angle which is defined as a rotation angle of the input face image.

REFERENCE TO RELATED APPLICATION

This is a divisional application for applicant's former patentapplication Ser. No. 14/615,770 filed on Feb. 6, 2015, currentlypending.

BACKGROUND OF THE INVENTION

1. Fields of the Invention

This divisional application relates to a method for creating a facereplacement database, and more particularly, to the method with theeffect of replacing a face image by detecting a rotation angle of theface image and then replacing a region to be replaced of the face imageby a replaced image.

2. Descriptions of Related Art

Face replacement technology gains more attentions in recent years,primarily due to its wide scope of applicability in the fields ofmovies, entertainments and medical cosmetology. For example, when amovie is shot, a stuntman's face image is replaced by a main actor'sface image, so that the main actor no longer needs to perform an actionof high level of difficulty, and a cameraman needs not to avoid theangle of shooting at the stuntman's face. Such face replacementtechnique can ensure the safety of the main actor and improve theefficiency of shooting the film and saving the production costeffectively. In the aspect of entertainment, users may replace faceswith others to achieve the effect of having fun. In the aspect ofmedical cosmetology, patients requiring a plastic surgery may observedthe result of the surgery ahead of time before deciding whether or notto take the surgery in order to avoid unexpected results.

In a conventional face replacement technique, the feature points of animage to be replaced and a target image are calculated manually, so asto designate a region and an angle to be replaced, and then the range ofthe calculated feature points of the target image is replaced by a rangeof calculated feature points of the replaced image. However, thistechnique is applicable for the replacement of a single static imageonly, but is difficult to be applied for replacing dynamic images. Inaddition, it is necessary to manually mark the feature points of theimage to be replaced and the target image, and thus the operation isinconvenient to users and time-consuming. Color difference may occur atthe boundary of the replaced image easily, and thus the overall visualperception of the replaced image is unnatural. Furthermore, the methodof estimating a face angle applied in the replacement process is toocomplicated and takes lots of computation time. Therefore, thistechnique fails to provide a quick image replacement.

In view of the aforementioned problems, the inventor of the presentinvention based on years of experience in the related industry toconduct extensive researches and experiments, and finally designed aface replacement technique in accordance with the present invention toovercome the aforementioned problems of the prior art.

SUMMARY OF THE INVENTION

The present invention overcomes the drawbacks of the conventional facereplacement technique that requires the users to manually mark thefeature points of the image to be replaced and the target image andcauses tremendous inconvenience to the users, and the method ofestimating a face angle is time-consuming, and color difference mayoccur at the boundary of the replaced image easily and result in anunnatural visual perception of the replaced image.

To achieve the aforementioned objective, the present invention providesa method for creating a face replacement database by using a method forestimating the 3D vector angle from a 2D face image, wherein the methodfor estimating the 3D vector angle from a 2D face image comprises thesteps of: creating a feature vector template including a feature vectormodel of a plurality of different rotation angles; detecting a corner ofeye and a corner of mouth in a face image to be processed, and definingthe corners of eye and the corners of mouth as vertices of aquadrilateral respectively; defining a sharp point in a verticaldirection of the quadrilateral plane, and converting the vertices into3D coordinates, wherein the sharp point and the vertices of thequadrilateral form a quadrangular pyramid; computing the four vectorsfrom the sharp point to the four vertices whose coordinates are 3Dcoordinates to obtain a vector set, and matching the vector set with thefeature vector model to obtain an angle which has the shortest distancebetween a feature vector model and the vector set, and defining theangle value as a rotation angle of the input face image.

The method for creating a face replacement database comprising the stepsof creating a face database for storing a plurality of replaced imageswith a face image rotation angle by using the method for estimating a 3Dvector angle from a 2D face image, and defining a region to be replacedin the replaced image.

Preferably, the region to be replaced is a surface region formed by thevertices.

Preferably, the method for creating a face replacement database furthercomprises the steps of:

obtaining a center point from two adjacent vertices, and shifting thecenter point towards the exterior of the quadrilateral; and

using an arc to connect the vertices and the center point to form theregion to be replaced.

Preferably, the arc is a parabola, and the surface region is in theshape of a convex hull.

Preferably, the corner of eye and the corner of mouth are detected fromtwo eye regions and a mouth region of the face image respectively, and afirst leftmost point and a first rightmost point are obtained from a topedge of the eye region respectively, and a second leftmost point and asecond rightmost point mouth region are obtained from a bottom edge ofthe eye region respectively, and a center point is obtained from twoadjacent points between the second leftmost point and the secondrightmost point, and the center point is shifted towards the exterior ofthe quadrilateral, and an arc is used for connecting the first leftmostpoint, the first rightmost point, the second leftmost point, the secondrightmost point and the center point to form a closed surface regionwhich is defined as the region to be replaced.

In summation of the description above, the present invention has thefollowing advantages and effects:

-   -   1. The present invention performs the steps of forming the        vertices of a quadrilateral through the corners of eye and        corners of mouth of a planar image, defining a sharp point in        the vertical direction of the quadrilateral, computing the four        vectors from the sharp point to four vertices whose coordinates        are 3D coordinates to obtain the vector set, matching the vector        set with the feature vector model to obtain an angle which has        the shortest distance between a feature vector model and the        vector set, and defining the angle value as the rotation angle        of the input face image. Obviously, the present invention can        estimate the rotation angle of a face image instantly without        any manual operation or complicated and huge computations. The        invention is applicable for dynamic and static images and almost        synchronized with the dynamic image without any delay.    -   2. The present invention defines and forms the region to be        replaced by the corners of eye and the corners of mouth in a        face image, so that the region to be replaced will change        according to the rotation of the face image, so that the face        replacement is done precisely without any deviation. In        addition, the values of the R channel, G channel and B channel        of the target replacing image are adjusted according to the zoom        factors between the RBG color of the replaced image and that of        the target replacing region, and the replaced image is pasted        onto the target replacing region by an edge feathering method,        so that the color of the target replacing region is made to be        natural.    -   3. The present invention simply requires a low cost camera and        personal computer, and does not require the installation of any        additional expensive equipment.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a flow chart of a method for estimating a 3D vector angle froma 2D face images in accordance with the present invention;

FIG. 2 is a schematic view of a first region of interest and a secondregion of interest defined in a face image in accordance with thepresent invention;

FIG. 3 is a schematic view of a vector set obtained from a face image inaccordance with the present invention;

FIG. 4 is a schematic view of a vector set of different rotation anglesof a face image in accordance with the present invention;

FIG. 5 is a flow chart of a method for creating a face replacementdatabase by using a 2D face image to estimate a 3D vector angle of theface image in accordance with the present invention;

FIG. 6 is a schematic view of a region to be replaced defined in areplaced image in accordance with the present invention;

FIG. 7 is a flow chart of a method for automatic video face replacementby using a 2D face image to estimate a 3D vector angle of the face imagein accordance with the present invention;

FIG. 8 is a schematic view of a region to be replaced defined in a faceimage in accordance with the present invention;

FIG. 9 is a schematic view of a region to be replaced pasted onto atarget replacing region in accordance with the present invention, and

FIG. 10 is a schematic view of an application of pasting a replacedimage onto a target replacing region of a face image in accordance withthe present invention.

DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT

The present invention will become more obvious from the followingdescription when taken in connection with the accompanying drawingswhich show, for purposes of illustration only, a preferred embodiment inaccordance with the present invention.

With reference to FIG. 1 for a method for estimating a 3D vector anglefrom a 2D face image in accordance with the present invention, themethod comprises the following steps of:

S001: Create a feature vector template, wherein the feature vectortemplate includes a feature vector model of a plurality of differentrotation angles and a standard eyes distance which is the distancebetween two eyes of the face image and used for scale normalization. Ingeneral, the feature vector model is created offline in advance. For ageneral user's face rotation, the rotation is performed within a rangeof rotation angles (say from −30° to 30°) with respect to the X-axis,Y-axis and Z-axis, so that if the X-axis, Y-axis and Z-axis arequantized into rotation units of N₁, N₂ and N₃ respectively, then afeature vector model containing N feature vectors is formed, and itsmathematical equation 1 is given below:N=N ₁ ×N ₂ ×N ₃  [Mathematical Equation 1]

Therefore, the vector rotation matrixes within a range of the rotationangles with respect to the X-axis, Y-axis and Z-axis are multiplied todefine a feature vector model.

S002: Capture a static or dynamic image by a camera such as a webcam orcapture a single face image 1 through a transmission network as shown inFIG. 2. In this preferred embodiment, Haar features is used as thefeatures for classification, and Cascade Adaboost classifier is used todetect a human face and facial features. To detect a corner of eye and acorner of mouth of the face image 1 effectively, a first region ofinterest 11 (ROI) is defined separately on both left and right halves ofan upper part of the face image 1 as two eye regions 12 in advance, anda second region of interest 13 is defined at a position within one-thirdof a lower part of the face image 1 as a mouth region 14, and a cornerof eye and a corner of mouth are searched from the eye region 12 and themouth region 14 respectively. Since this invention relates to thedetection of corners of eye and corners of mouth, the detection of acorner of eye is used as an example to illustrate the technicalcharacteristics of the invention, wherein the first region of interest11 is defined in the face image first, and after the first region ofinterest 11 is searched, a corner of eye is searched from the eye region12. In a preferred embodiment, the eye region 12 situated on the lefthalf of the face image 1 has a start point from the left side of theface image 1 for scanning the brightness of a skin region. Since theskin brightness of the corner of eye is darker than that of theneighborhood of the corner of eye, therefore the lowest scannedbrightness occurs at the corner of eye, and the eye region 12 situatedon the right half of the face image 1 similarly has a start point fromthe right side of the face image 1 for scanning the brightness of a skinregion to obtain the corner of eye. As to the search for the corner ofmouth, the same method for scanning the corner of eye is used, but thiscorner of eye and corner of mouth searching method is used for thepurpose of illustrating the present invention only, but not intended forlimiting the scope of the invention.

S003: Define the corner of eyes and the corners of mouth are thevertices P₁, P₂, P₃, P₄ of a quadrilateral respectively as shown in FIG.3. Since the size of each face image may not be the same due to thefactor of the shooting distance of each face image 1 from the camera,the distance from the vertices of corners of eye is computed for scalenormalization in order to determine the angle of the face image 1accurately and correct the error by the scale normalization. Since theface image 1 is a 2D image, the coordinates of the vertices are 2Dcoordinates. To standardize the rotation angle of each face image 1 fordifferent face images 1, this preferred embodiment computes the height hand the 2D coordinates (x₀, y₀) and the centroid G of the quadrilateral,while converting the vertices and the centroid into 3D coordinate, sothat the coordinate value of the vertices and the centroid G situated atthe third dimension is equal to 0. For example, the 3D coordinates ofthe centroid are represented by (x₀, y₀, 0), and a multiple constant kis defined, and a sharp point O is extended from the centroid G to apredetermined multiple of height h in a vertical direction of thequadrilateral plane. In other words, the sharp point O is defined at aposition of k times of the height h, such that the 3D coordinates of thesharp point O are represented by (x₀, y₀, kh), and the sharp point O andthe vertices P₁, P₂, P₃, P₄ of the quadrilateral form a quadrangularpyramids, and a scale normalization of the quadrangular pyramid isperformed according to the standard eyes distance and distance betweenthe vertices of the corners of eye, and the four vectors {right arrowover (QP₁)}, {right arrow over (QP₂)}, {right arrow over (QP₃)}, {rightarrow over (QP₄)} from the sharp point O to the vertices P₁, P₂, P₃, P₄are computed to obtain a vector set. In FIG. 4, different rotationangles of the face image 1 result in different quadrangular pyramids anddifferent vector sets.

S004: Compare the vector set with the feature vector model to obtain anangle which has the shortest distance between the feature vector modeland the vector set. Define the angle value as the rotation angle of theinput face image 1.

In FIG. 5, the present invention provides a method for creating a facereplacement database by using a 2D face image to estimate a 3D vectorangle of the face image, and the method comprises the following steps:

S005: Create a face database for storing a plurality of replaced imageswith a face image rotation angle by using the method for estimating a 3Dvector angle from a 2D face image, and obtain a replaced image 2 of therotation angle of the face image 1, wherein the replaced image 2 isobtained by capturing a face image 1 by a camera such as a webcam, andthe face image 1 may be a static or dynamic image, or by selecting anduploading a static or dynamic image by users, and the rotation angles ofthe face image 1 detected by the face angle estimation method are savedone by one to form the replaced image 2.

S006: Define a target replacing region 21 in the replaced image 2 toassure the replacement of the replacing portion by the replaced image 2,wherein the region to be replaced is a surface region formed by thevertices P₁, P₂, P₃, P₄. In a preferred embodiment, a center point C isobtained respectively between two adjacent vertices P₁, P₂, P₃, P₄, andthe center point C is shifted towards the exterior of the quadrilateral,and an arc is used for connecting the vertices and the center point toform a target replacing region 21. In order to provide a natural look ofthe replaced image 2, the arc is a parabola, and the surface region ispreferably in the shape of a convex hull. In FIG. 6, a first leftmostpoint P₅ and a first rightmost point P₆ are obtained from a top edge ofthe eye region 12, such that the first leftmost point P₅ and the firstrightmost point P₆ are higher than the vertices P₁, P₂ of the originalcorner of eye, and a second leftmost point P₇ and a second rightmostpoint P₈ are obtained from the bottom edge of the mouth region 14 suchthat the second leftmost point P₇ and the second rightmost point P₈ arelower than the vertices P₃, P₄ of the original corner of mouth, and acenter point C is obtained from two adjacent points between the firstleftmost point P₅, the first rightmost point P₆, the second leftmostpoint P₇ and the second rightmost point P₈, and the center point C isshifted towards the exterior of the quadrilateral, and an arc is usedfor connecting the first leftmost point P₅, the first rightmost pointP₆, the second leftmost point P₇, the second rightmost point P₈ and thecenter point C to form a closed surface region which is defined as thetarget replacing region 21.

With reference to FIG. 7 for a method for automatic video facereplacement by using a 2D face image to estimate a 3D vector angle ofthe face image, and the method comprises the following steps:

S007: Capture a face image 1 through a camera such as webcam, and theface image 1 may be a static or dynamic image, or select and upload astatic or dynamic face image 1 by users, and a rotation angle of theface image 1 is detected according to the method for estimating a 3Dvector angle from a 2D face image.

S008: Define a region to be replaced 15 in the face image 1 as shown inFIG. 8, wherein the region to be replaced 15 is defined by the samemethod of defining the target replacing region 21 in the aforementionedstep S006, and thus the method will not be repeated.

S009: Search the replaced image 2 with the rotation angle of thecorresponding face image 1, so that the target replacing region 21 ofone of replaced images 2 corresponding to the rotation angle of the faceimage 1 is pasted onto the region to be replaced 15.

S010: Since the sewing and processing portion of the face has beenprocessed by adjusting the color and brightness of the source image, andprocessing the boundary between sewing portions of the image, the resultmust be adjusted after the replacement takes place, so as to give a morenatural and coordinative image. However, the color and brightness of theregion to be replaced 15 and the target replacing region 21 have adifference to a certain extent, so that it is necessary to adjust thecolor and brightness of the target replacing region 21 to provide anatural visual effect of the replaced image. Therefore, the statisticsof the histograms of R channel, G channel and B channel in RGB colorspace of the region to be replaced 15 and the target replacing region 21are taken and normalized into a probability (i), while avoiding a blackregion from affecting the computation result. In the computationprocess, 0 is not included in the range, and the probability is used forcomputing the expected values of the region to be replaced 15 and targetreplacing region 21 as shown in the following mathematical equation 2:

$\begin{matrix}{E = {\sum\limits_{i = 1}^{n}\;{i\;{p(i)}}}} & \left\lbrack {{Mathematical}\mspace{14mu}{Equation}\mspace{14mu} 2} \right\rbrack\end{matrix}$

Therefore, zoom factors of the R channel, G channel and B channelbetween the region to be replaced 15 and the target replacing region 21are computed, and the values of the R channel, G channel and B channelof the target replacing region 21 are computed according to the zoomfactor as given in the following mathematical equation 3:C′ _(i) =C _(i) *w _(i) , i=1(B),2(G),3(R),  [Mathematical Equation 3]

S011: Although the color of the target replacing region 21 after beingreplaced may match the expected value of the color of the replacedregion, yet there may be a slight difference of the color and brightnessat the boundary. To compensate the color and bright difference, thetransparency value of the pixels at the boundary of the target replacingregion 21 or outside the boundary is set a higher value, and adecreasingly lower value at a position progressively moving towards theinside of an edge of the region to be replaced. The compensation can berepresented as the e following mathematical equation 4.I _(dst(x,y)) =αI _(src(x,y))+(1−α)I _(tgt(x,y))  [Mathematical Equation4]

Wherein, I_(dst(x,y)) is an image of the region after compensation;I_(src(x,y)) is an image of the target replacing region 21; I_(tgt(x,y))is an image of the region to be replaced 15, and a is the weight in therange [0,1], so that the image to be replaced 2 may be gradually layeredand pasted on the region to be replaced 15 by an edge feathering methodas shown in FIG. 10. As a result, a natural face image 1 is shown in theregion to be replaced 15 after being replaced.

While we have shown and described the embodiment in accordance with thepresent invention, it should be clear to those skilled in the art thatfurther embodiments may be made without departing from the scope of thepresent invention.

What is claimed is:
 1. A method for creating a face replacementdatabase, comprising: creating a face database for storing a pluralityof replacement face images, each replacement face image having arotation angle determined according to a method for estimating a 3-Dvector angle from a 2-D face image, and defining a target replacingregion in each replacement face image, wherein the method for estimatinga 3-D vector angle from a 2-D face image includes: creating a featurevector template including a feature vector model of a plurality ofdifferent rotation angles, detecting a corner of each of two eyes andtwo corners of a mouth in a face image to be processed, defining thecorners of the eyes and the two corners of the mouth as respectivevertices of a quadrilateral, defining a sharp point displaced in anorthogonal direction relative to the quadrilateral plane, converting thevertices into 3-D coordinates, wherein the sharp point and the verticesof the quadrilateral form a quadrangular pyramid, computing four 3-Dvectors, each 3-D vector extending from the sharp point to a respectiveone of the four vertices of the quadrilateral, wherein the coordinatesof said 3-D vectors are 3-D coordinates, and wherein said 3-D vectorsare computed to obtain a vector set, matching the vector set with thefeature vector model to obtain an angle which has the shortest distancebetween a feature vector model and the vector set, and defining theobtained angle value as a rotation angle of the input face image.
 2. Themethod for creating a face replacement database as claimed in claim 1,wherein the target replacing region is a surface region formed by thevertices of the quadrilateral.
 3. The method for creating a facereplacement database as claimed in claim 2, further comprising:obtaining a center point between two adjacent vertices of thequadrilateral; shifting the center point towards an exterior of thequadrilateral; and connecting the vertices and the center point with anarc, the arc thereby defining a boundary of the surface region.
 4. Themethod for creating a face replacement database as claimed in claim 3,wherein the arc is a parabola, and the surface region is in the shape ofa convex hull.
 5. The method for creating a face replacement database asclaimed in claim 2, wherein: the corners of the eyes are detected fromfirst and second eye regions of the face image, respectively, and thecorners of the mouth are detected from a mouth region of the face image,a first leftmost point and a first rightmost point are obtained from topedges of the first and second eye regions, respectively, and a secondleftmost point and a second rightmost point are obtained from a bottomedge of the mouth region, a center point is obtained from two adjacentpoints between the first leftmost point, the first rightmost point, thesecond leftmost point, and the second rightmost point, the center pointthen being shifted towards the exterior of the quadrilateral, and an arcconnects the first leftmost point, the first rightmost point, the secondleftmost point, the second rightmost point and the shifted center point,the arc thereby defining a boundary of the surface region.